<script src="view/resource/js/tinymce.min.js" referrerpolicy="origin"></script>


<div style="width: 1px;height: 20px;"></div>
<!-- general form elements disabled -->
<div class="card card-warning" style="width:90%;margin: 0 auto;">
  <div class="card-header">
    <h3 class="card-title">文章发布</h3>
  </div>
    <!-- /.card-header -->
  <div class="card-body">
    <form action="index.php?c=article&m=add" method="post">
      <div class="row">
        <div class="col-sm-12">
          <!-- text input -->
          <div class="form-group">
            <label>文章标题</label>
            <input type="text" class="form-control" name="article_title" placeholder="文章标题.......">
          </div>
        </div>
      </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label for="exampleInputFile">文章头图</label>
                    <div class="input-group">
                        <div class="custom-file">
                            <input type="file" class="custom-file-input" id="uploadImage">
                            <input type="hidden" name="article_image" id="uploadArticleImage">
                            <label class="custom-file-label" for="exampleInputFile">选择图片</label>
                        </div>
                        <div class="input-group-append" onclick="postData()">
                            <span class="input-group-text" id="upadd">上传</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
      <div class="row">
        <div class="col-sm-12">
          <div class="form-group">
            <label>文章描述</label>
            <textarea class="form-control" name="article_describe" rows="3" placeholder="文章描述 ..."></textarea>
          </div>
        </div>
      </div>

      <div class="row">
        <div class="col-sm-12">
          <!-- Select multiple-->
          <div class="form-group">
            <label>文章分类</label>
            <select multiple class="form-control" id="isshow" onchange="doSome();">
                <?php foreach ($data['class_list'] as $k=>$v){ ?>
                     <?php if($v['is_del'] == 0){ ?>
                         <option value="<?= $v['ac_id'] ?>"><?= $v['class_name'] ?></option>
                    <?php } ?>
                <?php } ?>
            </select>
            <input class="form-control form-control-lg" id="b_type" type="hidden" name="classify_id" value="1">
          </div>
        </div>

      </div>
      <div class="row">
          <div class="col-sm-12">
              <textarea id="mytextarea" name="article_content"></textarea>
          </div>
      </div>
        <br>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <div class="custom-control custom-switch">
                      <input type="checkbox" class="custom-control-input" name="is_recommend" id="customSwitch1">
                      <label class="custom-control-label" for="customSwitch1">是否推荐</label>
                    </div>
                  </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <div class="custom-control custom-switch">
                      <input type="checkbox" class="custom-control-input" name="article_status" id="customSwitch2">
                      <label class="custom-control-label" for="customSwitch2">是否上架</label>
                    </div>
                  </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label for="customRange1">排序</label>
                    <input type="range" class="custom-range" name="sort" id="customRange1">
                </div>
            </div>
        </div>

      <div class="card-footer">
          <button type="submit" class="btn btn-primary">提交</button>
      </div>
    </form>
  </div>
    <!-- /.card-body -->
</div>

<!--初始化tinymce-->
<script type="text/javascript">
    tinymce.init({
        selector: '#mytextarea',
        language: 'zh_CN',
        plugins: 'print preview searchreplace autolink directionality visualblocks visualchars fullscreen image link media template advcode codesample table charmap hr pagebreak nonbreaking anchor insertdatetime advlist lists wordcount imagetools textpattern help emoticons autosave bdmap indent2em autoresize formatpainter axupimgs importword',
        toolbar: 'code undo redo restoredraft | cut copy paste pastetext | forecolor backcolor bold italic underline strikethrough link anchor | alignleft aligncenter alignright alignjustify outdent indent | \
                     styleselect formatselect fontselect fontsizeselect | bullist numlist | blockquote subscript superscript removeformat | \
                     table image media charmap emoticons hr pagebreak insertdatetime print preview | fullscreen | bdmap indent2em lineheight formatpainter axupimgs importword',
        height: 650, //编辑器高度
        min_height: 400,
        /*content_css: [ //可设置编辑区内容展示的css，谨慎使用
            '/static/reset.css',
            '/static/ax.css',
            '/static/css.css',
        ],*/
        fontsize_formats: '12px 14px 16px 18px 24px 36px 48px 56px 72px',
        font_formats: '微软雅黑=Microsoft YaHei,Helvetica Neue,PingFang SC,sans-serif;苹果苹方=PingFang SC,Microsoft YaHei,sans-serif;宋体=simsun,serif;仿宋体=FangSong,serif;黑体=SimHei,sans-serif;Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Book Antiqua=book antiqua,palatino;Comic Sans MS=comic sans ms,sans-serif;Courier New=courier new,courier;Georgia=georgia,palatino;Helvetica=helvetica;Impact=impact,chicago;Symbol=symbol;Tahoma=tahoma,arial,helvetica,sans-serif;Terminal=terminal,monaco;Times New Roman=times new roman,times;Verdana=verdana,geneva;Webdings=webdings;Wingdings=wingdings,zapf dingbats;知乎配置=BlinkMacSystemFont, Helvetica Neue, PingFang SC, Microsoft YaHei, Source Han Sans SC, Noto Sans CJK SC, WenQuanYi Micro Hei, sans-serif;小米配置=Helvetica Neue,Helvetica,Arial,Microsoft Yahei,Hiragino Sans GB,Heiti SC,WenQuanYi Micro Hei,sans-serif',
        // link_list: [
        //     { title: '预置链接1', value: 'http://www.tinymce.com' },
        //     { title: '预置链接2', value: 'http://tinymce.ax-z.cn' }
        // ],
        // image_list: [
        //     { title: '预置图片1', value: 'https://www.tiny.cloud/images/glyph-tinymce@2x.png' },
        //     { title: '预置图片2', value: 'https://www.baidu.com/img/bd_logo1.png' }
        // ],
        image_class_list: [
            {title: 'None', value: ''},
            {title: 'Some class', value: 'class-name'}
        ],
        //importcss_append: true,
        //自定义文件选择器的回调内容
        file_picker_callback: function (callback, value, meta) {
            if (meta.filetype === 'file') {
                callback('https://www.baidu.com/img/bd_logo1.png', {text: 'My text'});
            }
            if (meta.filetype === 'image') {
                callback('https://www.baidu.com/img/bd_logo1.png', {alt: 'My alt text'});
            }
            if (meta.filetype === 'media') {
                callback('movie.mp4', {source2: 'alt.ogg', poster: 'https://www.baidu.com/img/bd_logo1.png'});
            }
        },
        //为内容模板插件提供预置模板
        templates: [
            {title: '模板1', description: '介绍文字1', content: '模板内容'},
            {
                title: '模板2',
                description: '介绍文字2',
                content: '<div class="mceTmpl"><span class="cdate">CDATE</span>，<span class="mdate">MDATE</span>，我的内容</div>'
            }
        ],
        //content_security_policy: "script-src *;",
        extended_valid_elements: 'script[src]',
        //
        template_cdate_format: '[CDATE: %m/%d/%Y : %H:%M:%S]',
        template_mdate_format: '[MDATE: %m/%d/%Y : %H:%M:%S]',
        autosave_ask_before_unload: false,
        toolbar_mode: 'wrap',
        images_upload_base_path: '/demo',
        images_upload_handler: function (blobInfo, succFun, failFun) {
            succFun('/demo/images/img.jpg');
        },
        //icons:'ax-color',
    });
    /*tinymce.activeEditor.uploadImages(function(success) {
        $.post('ajax/post.do', tinymce.activeEditor.getContent()).done(function() {
            console.log("Uploaded images and posted content as an ajax request.");
        });
    });*/
</script>


<script>
    function doSome(){
        var isshow = $("#isshow ").val();
        $('#b_type').val(isshow);
    }

</script>

<script type="text/javascript">
    function postData() {
        var imgs = $('#uploadImg')[0].files[0];
        var formData = new FormData();//新建一个formData来储存需要传递的信息
        formData.append('image', imgs);//需要传递的字段image路径
        formData.append('Authorization', '{$id}');//id
        $.ajax({
            type: 'POST',
            url: 'index.php?c=article&m=addImage',
            headers: {
                'yl-authorization': obj.mobile
            },
            data: formData,
            contentType:false,
            processData:false,
            dataType: 'json',
            success: function (data) {
                console.log(data);
            },
            error: function (err) {
            }
        });
    }
</script>


<!--<script type="text/javascript">-->
<!--    $(function () {-->
<!--        $('#upadd').click(function () {-->
<!--            var formData = new FormData();-->
<!--            formData.append('file', $('#exampleInputFile')[0].files[0]);  //添加图片信息的参数-->
<!--            $.post("index.php?c=article&m=addImage",{data: formData},function(result){-->
<!--                console.log(result);-->
<!--            },'json');-->
<!--        })-->
<!--    })-->
<!--</script>-->
